﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using Common.Base.Test;

namespace HXProject
{
    public class TestForSimpleCaculator : TestBase
    {
        protected override string Title => "简单计算器之加减乘除！";

        public double add(double a, double b)
        {
            return a + b;
        }
        public double sub(double a, double b)
        {
            return a - b;
        }
        public double mul(double a, double b)
        {
            return a * b;
        }
        public double div(double a, double b)
        {
            return a / b;

        }

        public override void OnRunTest()
        {
            double a, b;
            char c;
            TestForSimpleCaculator calculator = new TestForSimpleCaculator();
            Console.WriteLine("请输入第一个数：");
            a = Convert.ToDouble(Console.ReadLine());
            Console.WriteLine("请输入两个数之间的运算关系：");
            c = Convert.ToChar(Console.ReadLine());
            Console.WriteLine("请输入第二个数：");
            b = Convert.ToDouble(Console.ReadLine());
            if (c == '+')
            {
                Console.WriteLine("{0}+{1}={2}", a, b, calculator.add(a, b));
            }
            else if (c == '-')
            {
                Console.WriteLine("{0}-{1}={2}", a, b, calculator.sub(a, b));
            }
            else if (c == '*')
            {
                Console.WriteLine("{0}*{1}={2}", a, b, calculator.mul(a, b));
            }
            else
            {
                if (b == 0)
                {
                    Console.WriteLine("除数不能为0");
                }
                else
                {
                    Console.WriteLine("{0}/{1}={2}", a, b, calculator.div(a, b));
                }
            }
        }
    }
}
